home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / emstest3.zip / EMSFIX.CPP next >
C/C++ Source or Header  |  1994-05-11  |  6KB  |  233 lines

  1. /*
  2.     EMSFIX version 1.00
  3.     The MINIMALIST Group 4/20/94
  4.     Lewis Sellers 3
  5.     Written in Borland Turbo C++ 3.00
  6.  
  7.  
  8.     This is a companion program to EMSTEST.  It deallocates EMS page handles
  9.     that other programs may have forgotten about.  As this program
  10.     deallocates ALL handles, it is somewhat dangerous, so use it
  11.     with caution and common sense.
  12.  
  13.     It is primarily intended for use by programmers to regain expanded
  14.     memory after a alpha-test program goes arwy (ie. Abnormal program abortion).
  15.  
  16.     This program is in the PUBLIC DOMAIN.  All code and information herein
  17.     discussed (except of course references to The MINIMALIST Group and the
  18.     blessed Borland Turbo C++ 3.00) is free for public dispersment and
  19.     usage in whatsoever form desired.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <dos.h>
  24. #include <conio.h>
  25.  
  26. #define FALSE   0
  27. #define TRUE    !FALSE
  28.  
  29. main()
  30. {
  31.     union REGS regs;
  32.     union SREGS sregs;
  33.     char far *emptr,far *nameptr;
  34.     int n;
  35.     char far *emmstring,far *reference_string;
  36.     unsigned int handle;
  37.     unsigned int numberofhandles;
  38.     unsigned int cursorx,cursory;
  39.  
  40.     puts("\nEMSFIX quick version 1.00 (PUBLIC DOMAIN)");
  41.     puts("The Minimalist Group in-house developments 4/22/94");
  42.     puts("");
  43.  
  44.     /* Is the driver installed? Get the address of the EMS386 driver from
  45.     interrupt 0x67, where it always dwells, and then check to see if the
  46.     tag EMMXXXX0 is there.  If all this is true, there is an expanded memory
  47.     manager active here.  */
  48.     nameptr="EMMXXXX0";
  49.     regs.h.ah=0x35;
  50.     regs.h.al=0x67;
  51.     intdosx(®s,®s,&sregs);
  52.     emptr=(char *)MK_FP(sregs.es,0);
  53.  
  54.     emmstring=emptr+10;
  55.     reference_string=nameptr;
  56.     n=8;
  57.     while(*reference_string && n>0) {
  58.         if(*emmstring!=*reference_string) {
  59.             printf("EMS Driver not detected");
  60.             return 1;
  61.         }
  62.         n--;
  63.         emmstring++;
  64.         reference_string++;
  65.     }
  66.     puts("EMS Driver detected!");
  67.  
  68.  
  69.     /* is software operating? ask EMM driver if it is ON and taking requests */
  70.     regs.h.ah=0x40;
  71.     int86(0x67,®s,®s);
  72.  
  73.     switch (regs.h.ah) {
  74.         case 0x00:
  75.             puts("EMS is functional");
  76.             break;
  77.         case 0x80:
  78.             puts("Internal error in EMS software");
  79.             break;
  80.         case 0x81:
  81.             puts("Malfunction in EMS hardware");
  82.             break;
  83.         case 0x84:
  84.             puts("Undefined function");
  85.             break;
  86.         default:
  87.             puts("Undefined ERROR");
  88.     }
  89.  
  90.     /* look for page frame segment.  this is the segment in memory where
  91.     all the expanded memory is banked into as needed. Usually 0xe000.
  92.     it is VERY important for the program to remember this address, because
  93.     all the data you use with EMM can only dwell here at this segment! */
  94.     regs.h.ah=0x41;
  95.     int86(0x67,®s,®s);
  96.  
  97.     switch (regs.h.ah) {
  98.         case 0x00:
  99.             printf("Segment of page frame %u (%Xh)\n",regs.x.bx,regs.x.bx);
  100.             break;
  101.         case 0x80:
  102.             puts("Internal error in EMS software");
  103.             break;
  104.         case 0x81:
  105.             puts("Malfunction in EMS hardware");
  106.             break;
  107.         case 0x84:
  108.             puts("Undefined function");
  109.             break;
  110.         default:
  111.             puts("Undefined ERROR");
  112.     }
  113.  
  114.     /* get page count.  ask it how many 16k pages this system supports and
  115.     of those how many are actually free to be used by the next program ran. */
  116.     regs.h.ah=0x42;
  117.     int86(0x67,®s,®s);
  118.  
  119.     switch (regs.h.ah) {
  120.         case 0x00:
  121.             printf("Number of unallocated pages %u (%uk)\n",regs.x.bx,regs.x.bx*16);
  122.             printf("Total number of pages in system %u (%uk)\n",regs.x.dx,regs.x.dx*16);
  123.             break;
  124.         case 0x80:
  125.             puts("Internal error in EMS software");
  126.             break;
  127.         case 0x81:
  128.             puts("Malfunction in EMS hardware");
  129.             break;
  130.         case 0x84:
  131.             puts("Undefined function");
  132.             break;
  133.         default:
  134.             puts("Undefined ERROR");
  135.     }
  136.  
  137.     /* get EMM version.  the version as of this writting is 4.0 */
  138.     regs.h.ah=0x46;
  139.     int86(0x67,®s,®s);
  140.  
  141.     switch (regs.h.ah) {
  142.         case 0x00:
  143.             printf("EMM version number %u.%u\n",(regs.h.al>>4)&0xf,regs.h.al&0xf);
  144.             break;
  145.         case 0x80:
  146.             puts("Internal error in EMS software");
  147.             break;
  148.         case 0x81:
  149.             puts("Malfunction in EMS hardware");
  150.             break;
  151.         case 0x84:
  152.             puts("Undefined function");
  153.             break;
  154.         default:
  155.             puts("Undefined ERROR");
  156.     }
  157.  
  158.  
  159.     /* get handle count. ask how many groups of expanded memory are being
  160.     currently used. When asking for memory from EMM you specify how many
  161.     blocks of 16K pages you need for each data grouping.  That is, say I
  162.     need 64K to hold a 320x200 256 color background in memory.  I would
  163.     ask for 4 pages (of 16K giving me 64K total) and the expanded memory
  164.     manager would give me a handle number back (say, for example 17).
  165.     From then on out, when ever I need that infomation, I would ask EMM
  166.     to please bring the data at group 17 into memory at the frame segment.
  167.     This is sort of like validated parking where you get a number stub.
  168.     EMM parks the car/data somewhere (don't ask) and when ever you need it
  169.     you show it the stub number and it's brought around for you.
  170.     The following code asks EMM how many of these handles other programs
  171.     (mainly TSRs) are currently using. */
  172.     regs.h.ah=0x4B;
  173.     int86(0x67,®s,®s);
  174.     numberofhandles=regs.x.bx;
  175.     switch (regs.h.ah) {
  176.         case 0x00:
  177.             printf("Number of active EMS handles %u\n",regs.x.bx);
  178.             break;
  179.         case 0x80:
  180.             puts("Internal error in EMS software");
  181.             break;
  182.         case 0x81:
  183.             puts("Malfunction in EMS hardware");
  184.             break;
  185.         case 0x84:
  186.             puts("Undefined function");
  187.             break;
  188.         default:
  189.             puts("Undefined ERROR");
  190.     }
  191.  
  192.  
  193.     /* */
  194.     puts("Fixing undeallocated EMS handles...");
  195.     if(numberofhandles<=1) {
  196.         puts("  No handles allocated above the normal.");
  197.         puts("  EMS Fix aborted.");
  198.         return 1;
  199.     }
  200.     printf("  Deallocating handles 1 through ");
  201.     cursorx=wherex();
  202.     cursory=wherey();
  203.     for(n=1;n<numberofhandles;n++) {
  204.         regs.h.ah=0x45;
  205.         regs.x.dx=n;
  206.         int86(0x67,®s,®s);
  207.         gotoxy(cursorx,cursory);
  208.         printf("%u...",n);
  209.         switch (regs.h.ah) {
  210.             case 0x00:
  211.                 printf("  Success!                             ");
  212.                 break;
  213.             case 0x80:
  214.                 printf("  Internal error in EMS software       ");
  215.                 break;
  216.             case 0x81:
  217.                 printf("  Malfunction in EMS hardware          ");
  218.                 break;
  219.             case 0x84:
  220.                 printf("  Undefined function                   ");
  221.                 break;
  222.             case 0x86:
  223.                 printf("  Error in save/restore mapping context");
  224.             default:
  225.                 printf("  Undefined ERROR                      ");
  226.         }
  227.     }
  228.     printf("\n  Success!");
  229.     return 0;
  230. }
  231.  
  232. /* finis! */
  233.